package utiles.infoHWSWEquipo;

import java.io.IOException;
import java.util.Scanner;

class CPUWMI extends CPU{

	@Override
	public double getPorcentajeUsoCPU() {
		return getPorcentajeUsoCPU100()/100.0;
	}


	@Override
	public double getPorcentajeUsoCPU100() {
		String comando= "wmic cpu get loadpercentage";
		Scanner s= null;
		Process p;
		Runtime r= Runtime.getRuntime();
		double valor= 0;
		try {
			p= r.exec(comando);
			s= new Scanner(p.getInputStream());

			while(s.hasNext()){
				try{
					valor= Double.valueOf(s.nextLine());
					break;
				}catch(NumberFormatException nfe){}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		try{
			s.close();
		}catch(Exception e){}
		return valor;
	}
	
	public static void main(String[] args) {
		CPU c= new CPUWMI();
		for(int i= 0; i < 10; i++){
			System.out.println(i+" Uso CPU: "+c.getPorcentajeUsoCPU()*100);
			try{
				Thread.sleep(1000);
			}
			catch (InterruptedException e) {}
		}		
	}
}
